package com.bjc.base.web;

import com.bjc.base.bean.ResultVO;
import com.bjc.base.core.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import com.bjc.base.service.IPayLogService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import com.bjc.base.bean.request.PayLogReqVO;
import com.bjc.base.bean.response.PayLogVO;

/**
 * <p>
 * 用户收支记录 前端控制器
 * </p>
 *
 * @author 许自辉
 * @since 2018-06-10
 */
@RestController
@RequestMapping("api/book")
@Api(value = "payLog-api", tags = { "用户收支记录相关接口" })
public class PayLogController {

    @Autowired
    private IPayLogService payLogService;

	@ApiOperation("分页查询用户收支记录")
	@GetMapping("payLog/findPage")
	public ResultVO getPayLogPage(@RequestParam("pageNum") int pageNum, @RequestParam("pageSize") int pageSize,
			PayLogReqVO payLogReqVO) {
		PageHelper.startPage(pageNum, pageSize);
		List<PayLogVO> payLogVOs = payLogService.getList(payLogReqVO);
		return ResultGenerator.getSuccess(new PageInfo<PayLogVO>(payLogVOs));
	}
	
	@ApiOperation("分页查询用户收支记录")
	@GetMapping("payLog/find")
	public ResultVO getPayLoge(PayLogReqVO payLogReqVO) {
		PayLogVO payLogVO = payLogService.get(payLogReqVO);
		return ResultGenerator.getSuccess(payLogVO);
	}

	@ApiOperation("添加用户收支记录")
	@PostMapping("payLog/create")
	public ResultVO createPayLog(@RequestBody PayLogReqVO payLogReqVOs) {
		int count = payLogService.insert(payLogReqVOs);
		return ResultGenerator.getInsertSuccess(count);
	}

	@ApiOperation("更新用户收支记录")
	@PutMapping("payLog/update")
	public ResultVO updatePayLog(@RequestBody PayLogReqVO payLogReqVOs) {
		int count = payLogService.update(payLogReqVOs);
		return ResultGenerator.getUpdateSuccess(count);
	}

	@ApiOperation("批量删除用户收支记录")
	@DeleteMapping("payLog/deleteList")
	public ResultVO deletePayLog(@ApiParam(value = "payLog id集合") @RequestBody int[] ids) {
		int count = payLogService.deleteList(ids);
		return ResultGenerator.getDeleteSuccess(count);
	}

}
